package com.whosly.fast.web.quickly.filter.xss;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * 静态文件使用浏览器缓存
 */
@WebFilter(filterName = "browserCacheFilter", urlPatterns = {"*.css","*.jpg","*.js"})
public class BrowserCacheFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,ServletException{
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;

//		response.addHeader("Cache-Control","no-cache");
        response.addHeader("Cache-Control","max-age=86400"); //86400s=24h

        chain.doFilter(request,response);
    }

}
